Function.RegisterNamespace("Test.xUnit.js.Console");

[Fixture]
Test.xUnit.js.Console.ScriptLoader=function(){
    [Fixture]
    function ScriptLoader(){
        [Fact]
        function InstantiatesAttributeParser(){
            var mockAttributeParser=Mocks.GetMock(System.Script.Attributes,"AttributeParser",function(){
                actual=true;
            });
            var actual=false;
        
            mockAttributeParser(function(){
                new xUnit.js.Console.ScriptLoader();
            });
            
            Assert.True(actual);
        }

        [Fact]
        function InstantiatesEventManager(){
            var mockEventManager=Mocks.GetMock(System.Event,"EventManager",function(){
                actual=true;
            });
            var actual=false;
        
            mockEventManager(function(){
                new xUnit.js.Console.ScriptLoader();
            });
            
            Assert.True(actual);
        }

        [Fact]
        function SpecifiesNamedEventsAllowed(){
            var mockEventManager=Mocks.GetMock(System.Event,"EventManager",function(){
                actual=Array.prototype.slice.call(arguments,0);
            });
            var expected=["Loading","Success","Error","Loaded"];
            var actual=null;
        
            mockEventManager(function(){
                new xUnit.js.Console.ScriptLoader();
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function AssignsEventManagerToEventsProperty(){
            var mockEventManager=Mocks.GetMock(System.Event,"EventManager",function(){
                expected=this;
            });
            var expected=null;
            var actual=null;
        
            mockEventManager(function(){
                actual=new xUnit.js.Console.ScriptLoader().Events;
            });
            
            Assert.Equal(expected,actual);
        }
    }
    
    [Fixture]
    function GetScriptList(){
        [Fact]
        function ThrowsIfPathListIsABoolean(){
            var expected="xUnit.js.Console.ScriptLoader.GetScriptList: 'pathList' must be an array of valid file or Directory paths."
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.GetScriptList(true);
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfPathListIsADate(){
            var expected="xUnit.js.Console.ScriptLoader.GetScriptList: 'pathList' must be an array of valid file or Directory paths."
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.GetScriptList(new Date());
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfPathListIsAnError(){
            var expected="xUnit.js.Console.ScriptLoader.GetScriptList: 'pathList' must be an array of valid file or Directory paths."
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.GetScriptList(new Error());
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfPathListIsAFunction(){
            var expected="xUnit.js.Console.ScriptLoader.GetScriptList: 'pathList' must be an array of valid file or Directory paths."
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.GetScriptList(function(){});
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfPathListIsANumber(){
            var expected="xUnit.js.Console.ScriptLoader.GetScriptList: 'pathList' must be an array of valid file or Directory paths."
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.GetScriptList(7357);
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfPathListIsAnObject(){
            var expected="xUnit.js.Console.ScriptLoader.GetScriptList: 'pathList' must be an array of valid file or Directory paths."
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.GetScriptList({});
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfPathListIsAString(){
            var expected="xUnit.js.Console.ScriptLoader.GetScriptList: 'pathList' must be an array of valid file or Directory paths."
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.GetScriptList("test");
            });

            Assert.Equal(expected,actual);
        }

        // TODO: Needs more tests

    }
    
    [Fixture]
    function LoadScripts(){
        [Fact]
        function ThrowsIfScriptListIsABoolean(){
            var expected="xUnit.js.Console.ScriptLoader.LoadScripts: 'scriptList' must be an array of valid file paths.";
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.LoadScripts(true);
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfScriptListIsADate(){
            var expected="xUnit.js.Console.ScriptLoader.LoadScripts: 'scriptList' must be an array of valid file paths.";
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.LoadScripts(new Date());
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfScriptListIsAnError(){
            var expected="xUnit.js.Console.ScriptLoader.LoadScripts: 'scriptList' must be an array of valid file paths.";
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.LoadScripts(new Error());
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfScriptListIsAFunction(){
            var expected="xUnit.js.Console.ScriptLoader.LoadScripts: 'scriptList' must be an array of valid file paths.";
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.LoadScripts(function(){});
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfScriptListIsANumber(){
            var expected="xUnit.js.Console.ScriptLoader.LoadScripts: 'scriptList' must be an array of valid file paths.";
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.LoadScripts(7357);
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfScriptListIsAnObject(){
            var expected="xUnit.js.Console.ScriptLoader.LoadScripts: 'scriptList' must be an array of valid file paths.";
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.LoadScripts({});
            });

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ThrowsIfScriptListIsAString(){
            var expected="xUnit.js.Console.ScriptLoader.LoadScripts: 'scriptList' must be an array of valid file paths.";
            var target=new xUnit.js.Console.ScriptLoader();

            var actual=Record.Exception(function(){
                target.LoadScripts("test");
            });

            Assert.Equal(expected,actual);
        }

        // TODO: Needs more tests
    }
}